home *** CD-ROM | disk | FTP | other *** search
File List | 2001-02-06 | 4.6 KB | 176 lines |
-
- #line 12 "DIPSLIB.C"
-
- HINSTANCE g_hinstDll = ((void *)0);
-
-
-
-
-
- #pragma data_seg("Shared")
- HHOOK hHook = ((void *)0);
- DWORD dwApplicationThread = 0;
-
- static const TCHAR g_szRegSubKey[] = "Software\\Richter\\Desktop Item Position Saver";
-
- #pragma data_seg()
- #pragma comment(linker, "/section:Shared,rws")
-
-
-
- void SaveListViewItemPositions(HWND hwndLV)
- {
- int nItem, nMaxItems = (int)SendMessageA((hwndLV), (0x1000 + 4), 0, 0L);
- HKEY hkey;
- DWORD dwDisposition;
-
-
-
- RegDeleteKeyA ((( HKEY ) (ULONG_PTR)((LONG)0x80000001) ), g_szRegSubKey);
-
-
- RegCreateKeyExA ((( HKEY ) (ULONG_PTR)((LONG)0x80000001) ), g_szRegSubKey, 0, ((void *)0), (0x00000000L), (0x0002), ((void *)0), &hkey, &dwDisposition);
-
- for (nItem = 0; nItem < nMaxItems; nItem++)
- {
- TCHAR szName[260];
- POINT pt;
-
-
- { LVITEMA _ms_lvi; _ms_lvi.iSubItem = 0; _ms_lvi.cchTextMax = (sizeof(szName) / sizeof(szName[0])); _ms_lvi.pszText = szName; SendMessageA((hwndLV), (0x1000 + 45), (WPARAM)(nItem), (LPARAM)(LVITEMA *)&_ms_lvi);};
- (BOOL)SendMessageA((hwndLV), (0x1000 + 16), (WPARAM)(int)(nItem), (LPARAM)(POINT *)(&pt));
-
-
- RegSetValueExA (hkey, szName, 0, ( 3 ), (PBYTE) &pt, sizeof(pt));
- }
-
- RegCloseKey(hkey);
- }
-
-
-
- void RestoreListViewItemPositions (HWND hwndLV)
- {
- HKEY hkey;
- LONG l = RegOpenKeyExA((( HKEY ) (ULONG_PTR)((LONG)0x80000001) ), g_szRegSubKey,
- 0, (0x0001), &hkey);
- if (l == 0L) {
- int nIndex;
-
-
-
- DWORD dwStyle = ((DWORD)GetWindowLongA(hwndLV, (-16)));
- if (dwStyle & 0x0100) SetWindowLongA (hwndLV, (-16), dwStyle & ~0x0100);
-
- l = 0L;
- for (nIndex = 0; l != 259L; nIndex++) {
- TCHAR szName[260];
- POINT pt;
- LVFINDINFOA lvfi;
- int cbValueName = (sizeof(szName) / sizeof(szName[0]));
- int cbData = sizeof(pt), nItem;
- DWORD dwType;
-
-
- l = RegEnumValueA(hkey, nIndex, szName, &cbValueName,
- ((void *)0), &dwType, (PBYTE) &pt, &cbData);
-
- if (l == 259L)
- continue;
-
- if ((dwType == ( 3 )) && (cbData == sizeof(pt))) {
-
-
- lvfi.flags = 0x0002;
- lvfi.psz = szName;
- nItem = (int)SendMessageA((hwndLV), (0x1000 + 13), (WPARAM)(int)(-1), (LPARAM)(const LVFINDINFOA *)(&lvfi));
- if (nItem != -1) (BOOL)SendMessageA((hwndLV), (0x1000 + 15), (WPARAM)(int)(nItem), ((LPARAM)(DWORD)((LONG)(((WORD)((DWORD_PTR)((pt.x)) & 0xffff)) | ((DWORD)((WORD)((DWORD_PTR)((pt.y)) & 0xffff))) << 16))));
- }
- }
-
- SetWindowLongA(hwndLV, (-16), dwStyle);
- RegCloseKey(hkey);
- }
- }
-
-
-
- BOOL __stdcall DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID fImpLoad)
- {
- if (fdwReason == 1) g_hinstDll = hinstDll;
- return (1);
- }
-
-
-
- void DIPS_OnClose (HWND hwnd)
- {
- DestroyWindow (hwnd);
- }
-
- BOOL __stdcall DIPS_DlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- switch (uMsg)
- {
- case 0x8000:
- if (lParam) SaveListViewItemPositions((HWND) wParam);
- else RestoreListViewItemPositions((HWND) wParam);
- break;
-
- case (0x0010): return ((( (uMsg) == 0x0132 || (uMsg) == 0x0133 || (uMsg) == 0x0134 || (uMsg) == 0x0135 || (uMsg) == 0x0136 || (uMsg) == 0x0137 || (uMsg) == 0x0138 || (uMsg) == 0x0039 || (uMsg) == 0x002E || (uMsg) == 0x002F || (uMsg) == 0x0037 || (uMsg) == 0x0110 ) ? (BOOL)((((DIPS_OnClose))((hwnd)), 0L)) : (SetWindowLongA((hwnd), 0, (LPARAM)(LRESULT)((((DIPS_OnClose))((hwnd)), 0L))), 1)));
- }
-
- return (0);
- }
-
-
-
- LRESULT __stdcall GetMsgProc (int nCode, WPARAM wParam, LPARAM lParam)
- {
- static BOOL fFirstTime = 1;
-
- if (fFirstTime)
- {
- fFirstTime = 0;
-
- CreateDialogParamA(g_hinstDll, (LPSTR)((ULONG_PTR)((WORD)(101))), ((void *)0), DIPS_DlgProc, 0L);
-
- PostThreadMessageA (dwApplicationThread, 0x0000, 0, 0);
- }
-
- return (CallNextHookEx (hHook, nCode, wParam, lParam));
- }
-
-
-
- __declspec (dllexport) BOOL __stdcall SetDIPSHook(DWORD dwThreadId)
- {
- BOOL fOk = 0;
-
- if (dwThreadId != 0)
- {
-
-
-
- dwApplicationThread = GetCurrentThreadId();
-
-
- hHook = SetWindowsHookExA(3, GetMsgProc, g_hinstDll, dwThreadId);
- fOk = (hHook != ((void *)0));
- if (fOk) {
-
-
-
- fOk = PostThreadMessageA(dwThreadId, 0x0000, 0, 0);
- }
- }
- else
- {
- fOk = UnhookWindowsHookEx(hHook);
- hHook = ((void *)0);
- }
-
- return(fOk);
- }
-
-